package com.zuihai.app.mvp.ui.activity.base;

import android.support.v7.widget.AppCompatEditText;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.mvp.IPresenter;
import com.zuihai.app.R;
import com.zuihai.app.mvp.ui.widget.ToolbarWrapper;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/5/10 0010.
 */

public abstract class ToolBarBaseSearchActivity<P extends IPresenter> extends BaseActivity<P> {
    @BindView(R.id.toolbar)
    ToolbarWrapper toolbar;

    @BindView(R.id.fl_title)
    FrameLayout frameLayout;
    @BindView(R.id.iv_top_back)
    ImageView ivTopBack;
    @BindView(R.id.iv_top_search)
    ImageView ivTopSearch;
    @BindView(R.id.iv_top_edit)
    ImageView ivTopEdit;
    @BindView(R.id.et_search)
    AppCompatEditText etSearch;
    @BindView(R.id.tv_tobar_title_text)
    TextView mTitle;

    public ImageView getSearch(){
        return ivTopSearch;
    }

    public ImageView getImageEdit(){
        return ivTopEdit;
    }

    public AppCompatEditText getEditText(){
        return etSearch;
    }


    @Override
    protected void setupActivityComponent(AppComponent appComponent) {

    }

    @Override
    protected View initView() {
        //获取ToolbarLayout
        ViewGroup toolbarLayout = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.activity_top_bar_base_search, null, false);
        //找到内容容器
        ViewGroup contentContainer = (ViewGroup) toolbarLayout.findViewById(R.id.fl_title);
        //将内容放入到容器中
        LayoutInflater.from(this).inflate(initContentView(), contentContainer, true);
        return toolbarLayout;
    }

    protected abstract int initContentView();

    @Override
    protected void initBaseToolBar() {
        initBaseToolbar();
    }

    /**
     * 初始化Toolbar布局
     */
    private void initBaseToolbar() {
        setSupportActionBar(toolbar);
    }

    public boolean hasBack() {
        return true;
    }

    public ToolbarWrapper getToolbar() {
        return toolbar;
    }

    @OnClick(R.id.iv_top_back)
    public void onBack(View v) {
        onBackPressedSupport();
    }

    public void setTitle(String title){
        mTitle.setText(title);
    }
}
